﻿// ***************************************************************
// ** Sharepoint Workflow Monitor V. 1.0
// ** by Voltar - State of the Art Software
// ** 8916 Jonen, Switzerland
// ** www.voltar.ch
// ***************************************************************

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Workflow;


namespace WorkflowMonitorWebPart
{
    [Guid("39cb1759-3a72-4e72-8430-2d229ccabc34")]
    public class WorkflowMonitor : System.Web.UI.WebControls.WebParts.WebPart
    {
        public WorkflowMonitor()
        {
            
        }

        
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("Voltar Sharepoint Workflow Monitor - http://www.voltar.ch");
            writer.WriteBreak();
            
            foreach (SPList list in SPContext.Current.Web.Lists)
            {

                // Set the label's Text and ID properties.
                writer.Write("List: " + list.Title);
                writer.WriteBreak();
                SPWorkflowCollection spc = new SPWorkflowCollection(list);

                if (spc.Count > 0)
                {

                    writer.Indent++;

                    writer.Write("Workflows:");
                }

                writer.WriteBreak(); 
                for (int n = 0; n < spc.Count; n++)
                {
                    SPWorkflow spw = spc[n];
                   writer.Write(spw.ParentAssociation.Name);
                   
               
                   writer.Write(" Internal State: " + spw.InternalState.ToString());
                   writer.WriteBreak();
                   

                }
            }
        }

    }
}
